home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Font Fun / RotateAndReflect / RotateAndReflect.cs next >
Encoding:
Text File  |  2001-01-15  |  1.2 KB  |  40 lines

  1. //-----------------------------------------------
  2. // RotateAndReflect.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class RotateAndReflect: FontMenuForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new RotateAndReflect());
  14.      }
  15.      public RotateAndReflect()
  16.      {
  17.           Text = "Rotated and Reflected Text";
  18.  
  19.           strText = "Reflect";
  20.           font = new Font("Times New Roman", 36);
  21.      }
  22.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  23.      {
  24.           Brush        brush   = new SolidBrush(clr);
  25.           float        fAscent = GetAscent(grfx, font);
  26.           StringFormat strfmt  = StringFormat.GenericTypographic;
  27.  
  28.           grfx.TranslateTransform(cx / 2, cy / 2);
  29.  
  30.           for (int i = 0; i < 4; i++)
  31.           {
  32.                GraphicsState grfxstate = grfx.Save();
  33.  
  34.                grfx.RotateTransform(-45);
  35.                grfx.ScaleTransform((i > 1 ? -1 : 1), (i & 1) == 1 ? -1 : 1);
  36.                grfx.DrawString(strText, font, brush, 0, -fAscent, strfmt); 
  37.                grfx.Restore(grfxstate);
  38.           }
  39.      }
  40. }